import Vue from 'vue'
import Router from 'vue-router'
import error from '@/error'
import login from '@/login/login'
//平台
import ad from '../ad/ad';
import b_index from '../ad/b_index'
import ke_info from '../ad/ke_info'
import accss from '../ad/accss'
import limit from '../ad/limit'
import apply from '../ad/apply'
import setting from  '../ad/setting'

//客户
import market from '../market/market'
import customer_m from '../market/customer_m'
import co_index from '../market/co_index'
import unlock_record from '../market/unlock_record'
import usp_record from '../market/usp_record'
//长期用户
import cloudlock_view from '../cloudlock_view/cloudlock_view'
import user_m from '../cloudlock_view/user_m'
import longuser from '../cloudlock_view/longuser'
import lock_list from '../cloudlock_view/lock_list'
import authorized_ma from '../cloudlock_view/authorized_ma'
import permission_sets from '../cloudlock_view/permission_sets'
import configure from '../cloudlock_view/configure'
//import co_index from '../cloudlock_view/co_index'
//import setting from '../cloudlock_view/setting'

import store from '@/vuex/store.js'
import {makeRouter} from '@/js/unit.js'


Vue.use(Router)


const routers= [
    {
      path: '/',
      name: 'login',
      component: login
    },
    {
      path: '*',
      name: 'error',
      component:error
    }
  ]

const router=new Router({
  mode:'hash',
  routes:routers
})


const tree1=[
  {
    path: '/ad',
    name: 'ad',
    component:ad,
    children:[
      {
        path: 'b_index',
        name: 'b_index',
        component:b_index
      },
      {
        path: 'ke_info',
        name: 'ke_info',
        component:ke_info
      },
      {
        path: 'accss',
        name: 'accss',
        component:accss
      },
      {
        path: 'limit',
        name: 'limit',
        component:limit
      },
      {
        path: 'apply',
        name: 'apply',
        component:apply
      },
      {
        path: 'setting',
        name: 'setting',
        component:setting
      }
    ]
  }
]



const tree2=[
  {
    path: '/market',
    name: 'market',
    component:market,
    children:[
      {
        path: 'customer_m',
        name: 'customer_m',
        component:customer_m
      },
      {
        path: 'co_index',
        name: 'co_index',
        component:co_index
      },
      {
        path: 'unlock_record',
        name: 'unlock_record',
        component:unlock_record
      },
      {
        path: 'usp_record',
        name: 'usp_record',
        component:usp_record
      }
    ]
  }
]

const tree3=[
  {
    path: '/cloudlock_view',
    name: 'cloudlock_view',
    component:cloudlock_view,
    children:[
      {
        path: 'user_m',
        name: 'user_m',
        component:user_m
      },
      {
        path: 'longuser',
        name: 'longuser',
        component:longuser
      },
      {
        path: 'lock_list',
        name: 'lock_list',
        component:lock_list
      },
      {
        path: 'authorized_ma',
        name: 'authorized_ma',
        component:authorized_ma
      },
      {
        path: 'permission_sets',
        name: 'permission_sets',
        component:permission_sets
      },
      {
        path: 'configure',
        name: 'configure',
        component:configure
      },
      {
        path: 'co_index',
        name: 'co_index',
        component:co_index
      },
      {
        path: 'setting',
        name: 'setting',
        component:setting
      }
    ]
  }
]











 function Dyrouter(callback){
   const com=router.options.routes;
   const role=store.state.role;

   if(role==1){
          console.log(com)
          // com.forEach(item=>{
          //   if(item.name=='ad'){
          //     return;
          //   }
          // })
          router.addRoutes(tree1);
          callback(role);
         
    }else if(role==2){
         router.addRoutes(tree2);
         callback(role)
         
   }else if(role==3){
        router.addRoutes(tree3);
       callback(role)
        
    }
}






export default router
export { Dyrouter}
